package com.xj.qq;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xj.qq.domain.SQLuser;
import com.xj.qq.domain.SQlite;

public class Register extends AppCompatActivity {

    private SQlite mSQlite;
    private EditText username;
    private EditText userpassword;
    private String name;
    private String password;
    private Button reday;
    private Button back;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.qq_register);
        reday = (Button) findViewById(R.id.reday);
        back = (Button) findViewById(R.id.back);
        username = (EditText) findViewById(R.id.userName);
        userpassword = (EditText) findViewById(R.id.userpassword);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Register.this, QQLogin.class);
                startActivity(intent);
                finish();
            }
        });
        reday.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name = username.getText().toString().trim();
                password = userpassword.getText().toString().trim();
                if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(password)){
                    mSQlite.add(name, password);
                    SQLuser.getInstance(getApplicationContext()).insert(name,password);
                    SQLuser.getInstance(getApplicationContext()).close();
                    Intent intent1 = new Intent(Register.this, MainActivity.class);
                    intent1.putExtra("username", username.getText().toString());
                    intent1.putExtra("password", userpassword.getText().toString());
                    startActivity(intent1);
                    finish();
                    Toast.makeText(Register.this, "注册成功！", Toast.LENGTH_SHORT).show();
                } else{
                    Toast.makeText(Register.this, "请输入用户名或密码！", Toast.LENGTH_SHORT).show();
                }
            }
        });
        mSQlite = new SQlite(Register.this);
    }
}
